define([
	"UtilDir/util",
	"UtilDir/tool",
    "UtilDir/org/selectOrg",
    "UtilDir/searchBlock",
    "static/app/hddc/hddccjcommon/hddccjCommon",
	"Date","DateCN", "css!DateCss",
	"EasyUI","EasyUI-lang"
    ],function(Util, Tool, SelectOrg, SearchBlock,HddccjCommon){

    var sysPath =  getServer() + "/static/app/hddc/hddcB1PaleoEQEvent";

    var hddcB1PaleoeqeventFormHtml = sysPath + "/views/hddcB1PaleoeqeventForm.html";
	var getHddcB1PaleoeqeventController = function(){
		return getServer() + "/hddc/hddcB1Paleoeqevents";
	};

	/**
	 * 页面初始化
	 */
	var init = function(){
        initSearchBlock();
        queryBtnBind();
		initQualityinspectionStatusSelect()
		/*initProvinceSelect();
		initCitySelect();
		initAreaSelect();*/
		initcreateProvince();
        HddccjCommon.initProjectSelect("projectNameCondition"); //初始化查询的项目名称
		createHddcB1PaleoeqeventGrid();
	};
	var initcreateProvince = function () {
		var html = "";
		$("#citySelect").append(html);
		$("#areaSelect").append(html);
		$.ajax({
			url: getServer() + "/divisions/root/subdivisions",
			contentType: "application/json",
			type: "get",
			success: function (data) {
				$.each(data, function (idx, item) {
					html += "<option value='" + item.divisionName + "' exid='" + item.divisionId + "'>" + item.divisionName + "</option>";
				});
				$("#provinceSelect").append(html);
			}
		});
		$("#provinceSelect").change(function () {
			var html = '<option value="" disabled selected style="display:none;">请选择</option>';
			$("#citySelect option").remove();
			$("#citySelect").append(html);
			$("#areaSelect option").remove();
			$("#areaSelect").append(html);
			var divisionId = $(this).find("option:selected").attr("exid");
			if ($(this).val() == "北京市" || $(this).val() == "天津市" || $(this).val() == "上海市" || $(this).val() == "重庆市") {
				$("#citySelect").append("<option value='" + $(this).val() + "' exid='" + divisionId + "'>" + $(this).val() + "</option>");
				return;
			}
			$.ajax({
				url: getServer() + "/divisions/" + divisionId + "/subdivisions",
				contentType: "application/json",
				type: "get",
				success: function (data) {
					$.each(data, function (idx, item) {
						html += "<option value='" + item.divisionName + "' exid='" + item.divisionId + "'>" + item.divisionName + "</option>";
					});
					$("#citySelect").append(html);
				}
			});
		});
		$("#citySelect").change(function () {
			if ($(this).val() == "") return;
			var html = '<option value="" disabled selected style="display:none;">请选择</option>';
			$("#areaSelect option").remove();
			$("#areaSelect").append(html);
			var divisionId = $(this).find("option:selected").attr("exid");
			$.ajax({
				url: getServer() + "/divisions/" + divisionId + "/subdivisions",
				contentType: "application/json",
				type: "get",
				success: function (data) {
					$.each(data, function (idx, item) {
						html += "<option value='" + item.divisionName + "' exid='" + item.divisionId + "'>" + item.divisionName + "</option>";
					});
					$("#areaSelect").append(html);
				}
			});
		});
	}
	var initcreateProvinceForm = function () {
		var html = "";
		$("#city").append(html);
		$("#area").append(html);
		$.ajax({
			url: getServer() + "/divisions/root/subdivisions",
			contentType: "application/json",
			type: "get",
			success: function (data) {
				$.each(data, function (idx, item) {
					html += "<option value='" + item.divisionName + "' exid='" + item.divisionId + "'>" + item.divisionName + "</option>";
				});
				$("#province").append(html);
			}
		});
		$("#province").change(function () {
			var html = '<option value="" disabled selected style="display:none;">请选择</option>';
			$("#city option").remove();
			$("#city").append(html);
			$("#area option").remove();
			$("#area").append(html);
			var divisionId = $(this).find("option:selected").attr("exid");
			if ($(this).val() == "北京市" || $(this).val() == "天津市" || $(this).val() == "上海市" || $(this).val() == "重庆市") {
				$("#city").append("<option value='" + $(this).val() + "' exid='" + divisionId + "'>" + $(this).val() + "</option>");
				return;
			}
			$.ajax({
				url: getServer() + "/divisions/" + divisionId + "/subdivisions",
				contentType: "application/json",
				type: "get",
				success: function (data) {
					$.each(data, function (idx, item) {
						html += "<option value='" + item.divisionName + "' exid='" + item.divisionId + "'>" + item.divisionName + "</option>";
					});
					$("#city").append(html);
				}
			});
		});
		$("#city").change(function () {
			if ($(this).val() == "") return;
			var html = '<option value="" disabled selected style="display:none;">请选择</option>';
			$("#area option").remove();
			$("#area").append(html);
			var divisionId = $(this).find("option:selected").attr("exid");
			$.ajax({
				url: getServer() + "/divisions/" + divisionId + "/subdivisions",
				contentType: "application/json",
				type: "get",
				success: function (data) {
					$.each(data, function (idx, item) {
						html += "<option value='" + item.divisionName + "' exid='" + item.divisionId + "'>" + item.divisionName + "</option>";
					});
					$("#area").append(html);
				}
			});
		});
	}



	var editProvince = function (Province, City, Area) {
		debugger;
		var html = "";
		$("#city").append(html);
		$("#area").append(html);
		$.ajax({
			url: getServer() + "/divisions/root/subdivisions",
			contentType: "application/json",
			type: "get",
			success: function (data) {
				$.each(data, function (idx, item) {
					if (item.divisionName == Province) {
						debugger;
						var divisionId = item.divisionId;
						var htmlCity = '';
						if (Province == "北京市" || Province == "天津市" || Province == "上海市" || Province == "重庆市") {
							$("#city").append("<option value='" + Province + "' exid='" + divisionId + "'>" + Province + "</option>");
							$('#city').val(City);
							var htmlArea = '';
							$.ajax({
								url: getServer() + "/divisions/" + divisionId + "/subdivisions",
								contentType: "application/json",
								type: "get",
								success: function (data) {
									$.each(data, function (idx, item) {
										htmlArea += "<option value='" + item.divisionName + "' exid='" + item.divisionId + "'>" + item.divisionName + "</option>";
									});
									$("#area").append(htmlArea);
									$('#area').val(Area);
								}
							});

						} else {
							$.ajax({
								url: getServer() + "/divisions/" + divisionId + "/subdivisions",
								contentType: "application/json",
								type: "get",
								success: function (data) {
									debugger;
									$.each(data, function (idx, item) {
										if (item.divisionName == City) {
											var divisionId = item.divisionId;
											var htmlArea = '';
											$.ajax({
												url: getServer() + "/divisions/" + divisionId + "/subdivisions",
												contentType: "application/json",
												type: "get",
												success: function (data) {
													$.each(data, function (idx, item) {
														htmlArea += "<option value='" + item.divisionName + "' exid='" + item.divisionId + "'>" + item.divisionName + "</option>";
													});
													$("#area").append(htmlArea);
													$('#area').val(Area);
												}
											});
										}
										htmlCity += "<option value='" + item.divisionName + "' exid='" + item.divisionId + "'>" + item.divisionName + "</option>";
									});
									$("#city").append(htmlCity);
									$('#city').val(City);
								}
							});
						}
					}
					html += "<option value='" + item.divisionName + "' exid='" + item.divisionId + "'>" + item.divisionName + "</option>";
				});
				$("#province").append(html);
				$('#province').val(Province);
			}
		});
		$("#province").change(function () {
			var html = '<option value="" disabled selected style="display:none;">请选择</option>';
			$("#city option").remove();
			$("#city").append(html);
			$("#area option").remove();
			$("#area").append(html);
			var divisionId = $(this).find("option:selected").attr("exid");
			if ($(this).val() == "北京市" || $(this).val() == "天津市" || $(this).val() == "上海市" || $(this).val() == "重庆市") {
				$("#city").append("<option value='" + $(this).val() + "' exid='" + divisionId + "'>" + $(this).val() + "</option>");
				return;
			}
			$.ajax({
				url: getServer() + "/divisions/" + divisionId + "/subdivisions",
				contentType: "application/json",
				type: "get",
				success: function (data) {
					$.each(data, function (idx, item) {
						html += "<option value='" + item.divisionName + "' exid='" + item.divisionId + "'>" + item.divisionName + "</option>";
					});
					$("#city").append(html);
				}
			});
		});
		$("#city").change(function () {
			if ($(this).val() == "") return;
			var html = '<option value="" disabled selected style="display:none;">请选择</option>';
			$("#area option").remove();
			$("#area").append(html);
			var divisionId = $(this).find("option:selected").attr("exid");
			$.ajax({
				url: getServer() + "/divisions/" + divisionId + "/subdivisions",
				contentType: "application/json",
				type: "get",
				success: function (data) {
					$.each(data, function (idx, item) {
						html += "<option value='" + item.divisionName + "' exid='" + item.divisionId + "'>" + item.divisionName + "</option>";
					});
					$("#area").append(html);
				}
			});
		});
	}
	var initProvinceSelect = function () {
		$.ajax({
			url: getHddcB1PaleoeqeventController() + "/getValidDictItemsByDictCode/" + "",
			type: "get",
			success: function (data) {
				var mySelect = document.getElementById("provinceSelect");
				mySelect.add(new Option("请选择", ''), 0);
				for (var i = 0; i < data.length; i++) {
					var name = data[i].dictItemName;
					var code = data[i].dictItemCode;
					mySelect.add(new Option(name, code));
				}
			}
		});
	};
	var initCitySelect = function () {
		$.ajax({
			url: getHddcB1PaleoeqeventController() + "/getValidDictItemsByDictCode/" + "",
			type: "get",
			success: function (data) {
				var mySelect = document.getElementById("citySelect");
				mySelect.add(new Option("请选择", ''), 0);
				for (var i = 0; i < data.length; i++) {
					var name = data[i].dictItemName;
					var code = data[i].dictItemCode;
					mySelect.add(new Option(name, code));
				}
			}
		});
	};
	var initAreaSelect = function () {
		$.ajax({
			url: getHddcB1PaleoeqeventController() + "/getValidDictItemsByDictCode/" + "",
			type: "get",
			success: function (data) {
				var mySelect = document.getElementById("areaSelect");
				mySelect.add(new Option("请选择", ''), 0);
				for (var i = 0; i < data.length; i++) {
					var name = data[i].dictItemName;
					var code = data[i].dictItemCode;
					mySelect.add(new Option(name, code));
				}
			}
		});
	};

		var initProvinceSelectFrom = function () {
		$.ajax({
			url: getHddcB1PaleoeqeventController() + "/getValidDictItemsByDictCode/" + "",
			type: "get",
			success: function (data) {
				var mySelect = document.getElementById("province");
				mySelect.add(new Option("请选择", ''), 0);
				for (var i = 0; i < data.length; i++) {
					var name = data[i].dictItemName;
					var code = data[i].dictItemCode;
					mySelect.add(new Option(name, code));
				}
			}
		});
	};
		var initCitySelectFrom = function () {
		$.ajax({
			url: getHddcB1PaleoeqeventController() + "/getValidDictItemsByDictCode/" + "",
			type: "get",
			success: function (data) {
				var mySelect = document.getElementById("city");
				mySelect.add(new Option("请选择", ''), 0);
				for (var i = 0; i < data.length; i++) {
					var name = data[i].dictItemName;
					var code = data[i].dictItemCode;
					mySelect.add(new Option(name, code));
				}
			}
		});
	};
		var initAreaSelectFrom = function () {
		$.ajax({
			url: getHddcB1PaleoeqeventController() + "/getValidDictItemsByDictCode/" + "",
			type: "get",
			success: function (data) {
				var mySelect = document.getElementById("area");
				mySelect.add(new Option("请选择", ''), 0);
				for (var i = 0; i < data.length; i++) {
					var name = data[i].dictItemName;
					var code = data[i].dictItemCode;
					mySelect.add(new Option(name, code));
				}
			}
		});
	};
		var initSlipfeatureSelectFrom = function () {
		$.ajax({
			url: getHddcB1PaleoeqeventController() + "/getValidDictItemsByDictCode/" + "FaultTypeCVDcdxz",
			type: "get",
			success: function (data) {
				var mySelect = document.getElementById("slipfeature");
				mySelect.add(new Option("请选择", ''), 0);
				for (var i = 0; i < data.length; i++) {
					var name = data[i].dictItemName;
					var code = data[i].dictItemCode;
					mySelect.add(new Option(name, code));
				}
			}
		});
	};
//质检状态下拉框赋值
	var initQualityinspectionStatusSelect = function () {
		$.ajax({
			url: getHddcB1PaleoeqeventController() + "/getValidDictItemsByDictCode/" + "hddcQualityResult",
			type: "get",
			success: function (data) {
				var mySelect = document.getElementById("qualityinspectionStatusSelect");
                $("#qualityinspectionStatusSelect option").remove();
				mySelect.add(new Option("请选择", ''), 0);
				for (var i = 0; i < data.length; i++) {
					var name = data[i].dictItemName;
					var code = data[i].dictItemCode;
					mySelect.add(new Option(name, code));
				}
			}
		});
	};
	var initSearchBlock = function(){
        SearchBlock.init("searchBlock");
	};
	var queryBtnBind = function(){
        $("#btnSearch").click(function () {
            createHddcB1PaleoeqeventGrid();
        });
        $("#btnReset").click(function () {
            $("#provinceSelect").val("");$("#qualityinspectionStatusSelect").val("");
	            $("#citySelect").val("");
	            $("#areaSelect").val("");
				$("#projectNameCondition").val("");
			});
	};
    //导入
    var importForm = function () {

        $("#uploadModal").modal();
        $("#uploadModal").on("shown.bs.modal", function () {
            var url = getServer() + "/excel/探槽古地震事件.xls";
            $("#downloadZwExcelTemplate").attr("href", url);
        });

        $('#uploadButton').off("click");
        $("#uploadButton").on("click", function () {
            var uploadinput = document.getElementById("uploadFile");
            if (uploadinput.value == "") {
                Util.alert("上传前请先选择文件!");
                return;
            }
            var formData = new FormData();
            formData.append("file", uploadinput.files[0]);
            $.ajax({
                url: getHddcB1PaleoeqeventController() + "/importDisaster",
                data: formData,
                processData: false, //因为data值是FormData对象，不需要对数据做处理。
                contentType: false,
                type: "POST",
                success: function (data) {
                    $('#uploadModal').modal('hide');
                    uploadinput.value = null;
                    Util.alert(data);
                    createHddcB1PaleoeqeventGrid();
                }
            });
        });
    };
    //导出
    var exportForm = function () {
        var province = $("#provinceSelect").val();var qualityinspectionStatus = $("#qualityinspectionStatusSelect").val();
        var city = $("#citySelect").val();
        var area = $("#areaSelect").val();
        var projectName = $("#projectNameCondition").val();
        window.location.href = getHddcB1PaleoeqeventController() + "/exportFile?province=" + province + "&qualityinspectionStatus=" + qualityinspectionStatus+"&city="+city+"&area="+area+"&projectName="+projectName;
    };
	var createHddcB1PaleoeqeventGrid= function() {
        $("#hddcB1PaleoeqeventGrid").datagrid({
            url:getHddcB1PaleoeqeventController() + "/queryHddcB1Paleoeqevents",
			method:"GET",
            fitColumns: true,
            autoRowHeight: false,
            columns:[[
                {field:"ck",checkbox:true},
				{
					field: 'id',sortable:true,
					title:'记录编号',
					width:'20%',
					align:'center',
					formatter:function(value,rowData,rowIndex){
						return '<a href="#" onclick="_editHddcB1Paleoeqevent(\'' + rowData.uuid + '\');"> '+rowData.id+' </a> '
					}
				},
				{
					field:'province',sortable:true,
					title:'省',
					width:'20%',
					align:'center',
				},
				{
					field:'city',sortable:true,
					title:'市',
					width:'20%',
					align:'center',
				},
				{
					field:'area',sortable:true,
					title:'区（县）',
					width:'20%',
					align:'center',
				},

				{
					field:'projectName',
					title:'项目名称',
					width:'20%',
					align:'center',

				},
				{
					field:'taskName',
					title:'任务名称',
					width:'20%',
					align:'center',
				},

				{
					field:'trenchid',
					title:'探槽编号',
					width:'20%',
					align:'center',
				},
				{
					field:'qualityinspectionStatus',
					title:'质检状态',
					width:'20%',
					align:'center',
                    formatter:function(value,rowData,rowIndex){
                        if (rowData.qualityinspectionStatus == 1) {
                            return "系统质检通过";
                        }else if(rowData.qualityinspectionStatus == 2) {
                            return "<span style='color: red;'>系统质检未通过</span>";
                        }else if(rowData.qualityinspectionStatus == 3){
                            return "人工质检通过";
                        }else if(rowData.qualityinspectionStatus == 4){
                            return "<span style='color: red;'>人工质检未通过</span>";
                        }else{
                            return "未质检";
                        }
                    }
				},
                {
                    field:'createUser',
                    title:'上传人',
                    width:'20%',
                    align:'center'
                },
                {
                    field:'updateTime',
                    title:'上传时间',
                    width:'20%',
                    align:'center',
                },
            ]],
            toolbar: [{
                iconCls: 'fa fa-trash-o',
                text:"删除",
                handler: function(){
                    deleteHddcB1Paleoeqevent();
                }
            },{
                iconCls: 'fa fa-download',
                text: "导出",
                handler: function () {
                    exportForm();
                }
            }],
            queryParams:{
                province: $("#provinceSelect").val(),
                city: $("#citySelect").val(),
                area: $("#areaSelect").val(),
				projectName: $("#projectNameCondition").val(),
				qualityinspectionStatus: $("#qualityinspectionStatusSelect").val(),
            },
            pagination: true,
            pageSize: 10
        });
    };
	var formValidator = function(){
        // 人工审核不通过原因必填
        $("#auditForm").validate({
            rules : {
                reason : {
                    required : true,
                }
            },
            messages : {
            }
        });
		$("#hddcB1PaleoeqeventForm").validate({
			rules : {
                extends4 : {
                    required : true,
                },
				province : {
					required : true,
				},
				city : {
					required : true,
				},
				area : {
					required : true,
				},
				projectName : {
					required : true,
				},
				taskName : {
					required : true,
				},
				id : {
					required : true,
                    rangelength:[17,17]
				},
				trenchid : {
					required : true,
				},
				occurdateest : {
					maxlength : 8,
					number : true,
				},
				occurdateer : {
					maxlength : 8,
					number : true,
				},
				offsetest : {
					maxlength : 8,
					number : true,
				},
				offseter : {
					maxlength : 8,
					number : true,
				},
			},
			messages : {
				province : {
					required : "省不允许为空!",
				},
				city : {
					required : "市不允许为空!",
				},
				area : {
					required : "区（县）不允许为空!",
				},
				projectName : {
					required : "项目名称不允许为空!",
				},
				taskName : {
					required : "任务名称不允许为空!",
				},
				id : {
					required : "记录编号不允许为空!",
                    rangelength:"长度为17位!"
				},
				trenchid : {
					required : "探槽编号不允许为空!",
				},
				occurdateest : {
					required : "古地震发生时间要不为空的长度不大于8的浮点数!",
				},
				occurdateer : {
					required : "古地震发生时间误差要不为空的长度不大于8的浮点数!",
				},
				offsetest : {
					required : "同震位移 [ [米]]要不为空的长度不大于8的浮点数!",
				},
				offseter : {
					required : "同震位移误差值要不为空的长度不大于8的浮点数!",
				},
			}
		});
	};
    var initDatetimePicker = function () {
        // $("#occurdateest").datetimepicker({
        //     //设置使用语言：cn是自定义的中文版本，还可以扩展其他语言版本
        //     language: "cn",
        //     //输出格式化
        //     format: 'yyyymmdd',
        //     //直接选择‘今天’
        //     todayBtn: true,
        //     //设置最精确的时间选择视图
        //     minView: 'month',
        //     //高亮当天日期
        //     todayHighlight: true,
        //     //选择完毕后自动关闭
        //     autoclose: true
        // });
    }
	var getHddcB1Paleoeqevent = function(id){
		$.ajax({
			url: getHddcB1PaleoeqeventController() + "/"+id,
			type: "get",
			success: function (data) {
				editProvince(data.province, data.city, data.area);
                HddccjCommon.viewFileUpload(data.extends8);// 回显附件
                // 回显项目名称
                // $("#projectName").val(data.projectName);
                // 回显任务名称
                HddccjCommon.initEditTaskSelect("taskName",data.projectName);

                if(data.qualityinspectionStatus == "3" && data.extends10 == "2"){$(".qualityControlBox").css("display","none");}
				Tool.deserialize("hddcB1PaleoeqeventForm", data);
				if(data.qualityinspectionStatus == '2' || data.qualityinspectionStatus == '4') {
					$('#failReason').css('display','block')
                    // 质检不通过原因
                    var text = '';var num = 0;
                    if(data.qualityinspectionComments!=null && data.qualityinspectionComments!="") text=text+ ++num+'、'+data.qualityinspectionComments+'\n';
                    if(data.extends1!=null && data.extends1!="") text=text+ ++num+'、'+data.extends1+'\n';
                    if(data.extends2!=null && data.extends2!="") text=text+ ++num+'、'+data.extends2+'\n';
                    if(data.extends3!=null && data.extends3!="") text=text+ ++num+'、'+data.extends3+'\n';
                    Tool.deserialize("auditForm", {reason: text});
				}
			}
		});
	};

	var addHddcB1Paleoeqevent = function () {
		var slidebar = Util.slidebar({
			url: hddcB1PaleoeqeventFormHtml,
			width: "800px",
			cache: false,
			close : true,
			afterLoad: function () {
				/*initProvinceSelectFrom();
				initCitySelectFrom();
				initAreaSelectFrom();*/
				initQualityinspectionStatusSelect()
				initcreateProvinceForm();
				initSlipfeatureSelectFrom();
				formValidator();
                HddccjCommon.initProjectSelect("projectName"); //添加页面项目名称下拉
                HddccjCommon.initTaskSelect("projectName", "taskName"); //添加页面任务名称根据项目名称切换
				$("#saveBtn").on("click", function () {
					if($("#hddcB1PaleoeqeventForm").valid()){
						var data = Tool.serialize("hddcB1PaleoeqeventForm");
                        // 保存项目任务id
                        data.projectId = $("#projectName").val();
                        data.taskId = $("#taskName").val();
						$.ajax({
							url: getHddcB1PaleoeqeventController() ,
                            contentType:"application/json",
							data: JSON.stringify(data),
							type: "post",
							success: function (data) {
								Util.alert(data.message);
								slidebar.close();
                                createHddcB1PaleoeqeventGrid();
							}
						});
					}
				});
			}
		});
	};
	window._editHddcB1Paleoeqevent = function(hddcB1PaleoeqeventId) {
		var slidebar = Util.slidebar({
			url: hddcB1PaleoeqeventFormHtml,
			width: "800px",
			cache: false,
			close : true,
			afterLoad: function () {
				/*initProvinceSelectFrom();
				initCitySelectFrom();
				initAreaSelectFrom();*/
				initSlipfeatureSelectFrom();
				formValidator();
                initDatetimePicker();
                HddccjCommon.initProjectSelect("projectName"); HddccjCommon.tipsInfo(); //编辑页面项目名称下拉
                HddccjCommon.initTaskSelect("projectName","taskName"); //编辑页面任务名称根据项目名称切换
				getHddcB1Paleoeqevent(hddcB1PaleoeqeventId);
                $("#saveBtn").on("click", function () {
                    if($("#hddcB1PaleoeqeventForm").valid()){
                        var data = Tool.serialize("hddcB1PaleoeqeventForm");
                        data.qualityinspectionStatus = 0; // 质检保存
                        // 保存项目任务id
                        data.projectId = $("#projectName").val();
                        data.taskId = $("#taskName").val();
                        $.ajax({
                            url: getHddcB1PaleoeqeventController()+"/update" ,
                            contentType:"application/json",
                            data: JSON.stringify(data),
                            type: "post",
                            success: function (data) {
                                Util.alert(data.message);
                                slidebar.close();
                                createHddcB1PaleoeqeventGrid();
                            }
                        });
                    }
                });
				// 审核通过
				$("#approved").on("click", function () {
					if ($("#hddcB1PaleoeqeventForm").valid()) {
						var data = Tool.serialize("hddcB1PaleoeqeventForm");
						data.qualityinspectionStatus = "3";data.extends10 = "2";
						//
						$.ajax({
							url: getHddcB1PaleoeqeventController()+"/update",
							contentType: "application/json",
							data: JSON.stringify(data),
							type: "post",
							success: function (data) {
                                Util.alert("质检成功！");
								slidebar.close();
								createHddcB1PaleoeqeventGrid()
							}
						});
					}
				});
// 审核不通过
				$("#unapproved").on("click", function () {
					if ($("#hddcB1PaleoeqeventForm").valid()) {
						if ($('#failReason').css('display') == 'none') {
							$('#failReason').css('display', 'block')
						} else {
							var data = Tool.serialize("hddcB1PaleoeqeventForm");
							data.qualityinspectionComments = $('#reason').val();
							data.qualityinspectionStatus = "4";data.extends10 = "1";data.extends1 = "";data.extends2 = "";data.extends3 = "";
							if ($("#auditForm").valid()) {
								$.ajax({
									url: getHddcB1PaleoeqeventController()+"/update",
									contentType: "application/json",
									data: JSON.stringify(data),
									type: "post",
									success: function (data) {
										Util.alert(data.message);
										slidebar.close();
										createHddcB1PaleoeqeventGrid()
										$('#failReason').css('display', 'none')
									}
								});
							}
						}
					}
				});
			}
		});
	};
	var deleteHddcB1Paleoeqevent = function() {
		var rows = $("#hddcB1PaleoeqeventGrid").datagrid("getSelections");
		if (rows == null || rows.length == 0) {
			Util.alert("请选择一行数据!");
			return;
		}
		Util.confirm("是否要删除选中的数据?", function() {
			var ids = "";
			$.each(rows, function(i, row){
				ids += row.uuid + ",";

			});
			ids = ids.substr(0,ids.length - 1);
			$.ajax({
				url: getHddcB1PaleoeqeventController()  +"/delete",
                contentType:"application/json",
                data: ids,
				type: "post",
				success: function (data) {
					createHddcB1PaleoeqeventGrid();
				}
			});
		}, function() {
			return;
		});

	};

	return {
		init:init
	};
});
